//
//  KuaiDiViewController.m
//  YaDiuDiu
//
//  Created by 欧洪飞 on 2017/8/30.
//  Copyright © 2017年 jy. All rights reserved.
//

#import "KuaiDiViewController.h"

#import "KDQGView.h"
#import "KDTCView.h"
#import "KDServerView.h"
#import "MapSelPlaceViewController.h"
#import "UITextView+JKInputLimit.h"
#import "UITextField+JKInputLimit.h"
#import "LoginViewController.h"
#import "NavViewController.h"

#import "PayForViewController.h"
#import "ManServiceViewController.h"
#import "AddressPickerView.h"
#import "SelectHouseTypeView.h"
@interface KuaiDiViewController ()<UITextViewDelegate,UIPickerViewDelegate,UIPickerViewDataSource,MapSelPlaceViewControllerDelegate,AddressPickerViewDelegate>{
    UIButton *btn1;
    UIButton *btn2;
    KDQGView *view1;
    KDTCView *tcView;
    UIView *view2;
    NSMutableArray *array;//快递公司
    
    UIScrollView *sclView;
    UIView *footView;//快递view
    UIView *bottomView;//省市区view
    KDServerView *serverView;//
    NSString *_lat;
    NSString *_lng;
    NSString *_lat1;
    NSString *_lng1;
    NSString *_lat2;
    NSString *_lng2;
    UIView *_pickerContent;
}

@property (nonatomic,strong)UIPickerView *picker;//快递商家
@property (nonatomic,strong)UIPickerView *pickerView;//省市区
@property (nonatomic,copy)NSString *kdid;//快递商家id

@property (nonatomic,strong)UIButton *button1;
@property (nonatomic,strong)UIButton *button2;
@property (nonatomic,strong)UIButton *button3;
@property (nonatomic,strong)UIButton *button4;
@property (nonatomic,copy)UILabel *labLine;

@property (nonatomic,strong)NSDictionary *dic;//价格数据

@property (nonatomic, strong) NSMutableArray *regionArray;//城市列表数据源

@property (nonatomic, assign) NSInteger provinceIndex,cityIndex,districtIndex;

@property (nonatomic,copy)NSString *Province;//省市区
@property (nonatomic,copy)NSString *City;
@property (nonatomic,copy)NSString *Area;

@property (nonatomic,copy)NSString *orderNum;//订单号

@property (nonatomic,copy)NSString *placeState;//地址标示

@property (nonatomic,copy)NSString *carType;//车辆信息

@property (nonatomic,copy)NSString *km;//行程 距离

@property (nonatomic,strong)NSDictionary *priceKm;//同城快递价格获取

@property (nonatomic,copy)NSString *tcPrice;//

@end

@implementation KuaiDiViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self showNav:@"快递"];
    array = [NSMutableArray array];
    self.view.backgroundColor = COLOR_RGB(242, 242, 242, 1);
    [self loadUI];
    //快递列表
    [self loadData];
    [self loadNum];
    
    self.provinceIndex = self.cityIndex = self.districtIndex = 0;
    //
    NSString * path = [[NSBundle mainBundle] pathForResource:@"Province" ofType:@"plist"];
    self.regionArray = [[NSMutableArray alloc] initWithContentsOfFile:path];
    
}

//生成订单号
- (void)loadNum{
    NSString *url = [NSString stringWithFormat:@"%@/App/Shoppingcart/ordernumber",urlHead];
    [[AFHTTPSessionManager manager] POST:url parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"res:%@",responseObject);
        _orderNum = [responseObject objectForKey:@"result"];
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"error:%@",error);
    }];
    
}

- (void)loadUI{
    btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
    btn1.frame = CGRectMake((ScreenWidth-200)/3, 74, 100, 30);
    btn1.layer.cornerRadius = 10.0;
    btn1.backgroundColor =COLOR_RGB(253, 17, 66, 1);;
    btn1.titleLabel.font = [UIFont systemFontOfSize:15.0];
    [btn1 setTitle:@"全国快递" forState:UIControlStateNormal];
    [btn1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btn1 addTarget:self action:@selector(click1) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn1];
    
    btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
    btn2.frame = CGRectMake((ScreenWidth-200)/3*2+100, 74, 100, 30);
    btn2.layer.cornerRadius = 10.0;
    btn2.layer.borderWidth = 1.0;
    btn2.layer.borderColor = COLOR_RGB(253, 17, 66, 1).CGColor;
    btn2.titleLabel.font = [UIFont systemFontOfSize:15.0];
    [btn2 setTitle:@"同城快递" forState:UIControlStateNormal];
    [btn2 setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [btn2 addTarget:self action:@selector(click2) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn2];
    
    sclView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, btn2.frame.origin.y+btn2.frame.size.height+10, ScreenWidth, ScreenHeight-50-64)];
    sclView.contentSize = CGSizeMake(ScreenWidth, 667);
    [self.view addSubview:sclView];
    //全国快递view
    view1 = [[[NSBundle mainBundle] loadNibNamed:@"KDQGView" owner:nil options:nil] lastObject];
    view1.frame = CGRectMake(0, 0, ScreenWidth, 700);
    [sclView addSubview:view1];
    
    view1.textView.layer.cornerRadius = 5.0;
    view1.textView.layer.borderWidth = 1.0;
    view1.textView.layer.borderColor = COLOR_RGB(230, 230, 230, 1).CGColor;
    view1.textView.text = @"请填写";
    view1.textView.delegate = self;
    view1.textView.textColor = [UIColor grayColor];
    //全国快递呼叫
    [view1.btnHJ addTarget:self action:@selector(clickHJ) forControlEvents:UIControlEventTouchUpInside];
    //选择快递
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickKD)];
    view1.labSelKD.userInteractionEnabled = YES;
    [view1.labSelKD addGestureRecognizer:tap];
    //全国快递取件地址
    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(click1QG)];
    view1.view1.userInteractionEnabled = YES;
    [view1.view1 addGestureRecognizer:tap1];
    
    //选择省市区
    UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(click2QG)];
    view1.labGOPlace.userInteractionEnabled = YES;
    [view1.labGOPlace addGestureRecognizer:tap2];
    
    
    //同城快递
    view2 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 950)];
    [sclView addSubview:view2];
    view2.hidden = YES;
    //车型
    UIView *viewH = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 100)];
    viewH.backgroundColor = [UIColor whiteColor];
    [view2 addSubview:viewH];
    //
    _button1 = [UIButton buttonWithType:UIButtonTypeCustom];
    _button1.frame = CGRectMake(0, 10, ScreenWidth/4, 90);
    [_button1 setTitle:@"电动车" forState:UIControlStateNormal];
    _button1.titleLabel.font = [UIFont systemFontOfSize:13.0];
    [_button1 setTitleColor:COLOR_RGB(10, 11, 12, 1) forState:UIControlStateNormal];
    [_button1 setImage:[UIImage imageNamed:@"-电动车"] forState:UIControlStateNormal];
    _button1.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [_button1 setTitleEdgeInsets:UIEdgeInsetsMake(0, -_button1.imageView.frame.size.width, -_button1.imageView.frame.size.height, 0)];
    [_button1 setImageEdgeInsets:UIEdgeInsetsMake(-_button1.titleLabel.intrinsicContentSize.height-10, 0, 0, -_button1.titleLabel.intrinsicContentSize.width)];
    [_button1 addTarget:self action:@selector(clickCar1) forControlEvents:UIControlEventTouchUpInside];
    [viewH addSubview:_button1];
    //三轮
    _button2 = [UIButton buttonWithType:UIButtonTypeCustom];
    _button2.frame = CGRectMake(ScreenWidth/4, 10, ScreenWidth/4, 90);
    [_button2 setTitle:@"三轮车" forState:UIControlStateNormal];
    _button2.titleLabel.font = [UIFont systemFontOfSize:13.0];
    [_button2 setTitleColor:COLOR_RGB(10, 11, 12, 1) forState:UIControlStateNormal];
    [_button2 setImage:[UIImage imageNamed:@"图层-4"] forState:UIControlStateNormal];
    _button2.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [_button2 setTitleEdgeInsets:UIEdgeInsetsMake(0, -_button2.imageView.frame.size.width, -_button2.imageView.frame.size.height, 0)];
    [_button2 setImageEdgeInsets:UIEdgeInsetsMake(-_button2.titleLabel.intrinsicContentSize.height-10, 0, 0, -_button2.titleLabel.intrinsicContentSize.width)];
    [_button2 addTarget:self action:@selector(clickCar2) forControlEvents:UIControlEventTouchUpInside];
    [viewH addSubview:_button2];
    //轿车
    _button3 = [UIButton buttonWithType:UIButtonTypeCustom];
    _button3.frame = CGRectMake(ScreenWidth/2, 10, ScreenWidth/4, 90);
    [_button3 setTitle:@"轿车" forState:UIControlStateNormal];
    _button3.titleLabel.font = [UIFont systemFontOfSize:13.0];
    [_button3 setTitleColor:COLOR_RGB(10, 11, 12, 1) forState:UIControlStateNormal];
    [_button3 setImage:[UIImage imageNamed:@"轿车"] forState:UIControlStateNormal];
    _button3.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [_button3 setTitleEdgeInsets:UIEdgeInsetsMake(0, -_button3.imageView.frame.size.width, -_button3.imageView.frame.size.height, 0)];
    [_button3 setImageEdgeInsets:UIEdgeInsetsMake(-_button3.titleLabel.intrinsicContentSize.height-10, 0, 0, -_button3.titleLabel.intrinsicContentSize.width)];
    [_button3 addTarget:self action:@selector(clickCar3) forControlEvents:UIControlEventTouchUpInside];
    [viewH addSubview:_button3];
    //货车
    _button4 = [UIButton buttonWithType:UIButtonTypeCustom];
    _button4.frame = CGRectMake(ScreenWidth/4*3, 10, ScreenWidth/4, 90);
    [_button4 setTitle:@"货车" forState:UIControlStateNormal];
    _button4.titleLabel.font = [UIFont systemFontOfSize:13.0];
    [_button4 setTitleColor:COLOR_RGB(10, 11, 12, 1) forState:UIControlStateNormal];
    [_button4 setImage:[UIImage imageNamed:@"货车"] forState:UIControlStateNormal];
    _button4.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [_button4 setTitleEdgeInsets:UIEdgeInsetsMake(0, -_button4.imageView.frame.size.width, -_button4.imageView.frame.size.height, 0)];
    [_button4 setImageEdgeInsets:UIEdgeInsetsMake(-_button4.titleLabel.intrinsicContentSize.height-10, 0, 0, -_button4.titleLabel.intrinsicContentSize.width)];
    [_button4 addTarget:self action:@selector(clickCar4) forControlEvents:UIControlEventTouchUpInside];
    [viewH addSubview:_button4];
    
    _labLine = [[UILabel alloc] initWithFrame:CGRectMake((ScreenWidth/4-50)/2, 98, 50, 2)];
    _labLine.backgroundColor = COLOR_RGB(3, 191, 222, 1);
    _labLine.hidden = YES;
    [viewH addSubview:_labLine];
    //view同城快递
    tcView = [[[NSBundle mainBundle] loadNibNamed:@"KDTCView" owner:nil options:nil] lastObject];
    tcView.frame = CGRectMake(0, viewH.frame.origin.y+viewH.frame.size.height+10, ScreenWidth, 850);
    [view2 addSubview:tcView];
    
    tcView.textView.layer.borderWidth = 1.0;
    tcView.textView.layer.cornerRadius = 5.0;
    tcView.textView.layer.borderColor = COLOR_RGB(230, 230, 230, 1).CGColor;
    tcView.textView.text = @"请填写";
    tcView.textView.delegate = self;
    tcView.textView.textColor = [UIColor grayColor];
    //同意协议
    [tcView.btnAgree addTarget:self action:@selector(clickAgree:) forControlEvents:UIControlEventTouchUpInside];
    //计价规则
    [tcView.btnJJGZ addTarget:serverView action:@selector(clickJJ) forControlEvents:UIControlEventTouchUpInside];
    //服务协议
    [tcView.btnServerse addTarget:self action:@selector(clickService) forControlEvents:UIControlEventTouchUpInside];
    //从地址
    UITapGestureRecognizer *tapTC1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clicktc1)];
    tcView.view1.userInteractionEnabled = YES;
    [tcView.view1 addGestureRecognizer:tapTC1];
    
    //到地址
    UITapGestureRecognizer *tapTC2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clicktc2)];
    tcView.view2.userInteractionEnabled = YES;
    [tcView.view2 addGestureRecognizer:tapTC2];
    
    //同城呼叫
    [tcView.btnHJ addTarget:self action:@selector(clickTChj) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    view1.textSHName.jk_maxLength  = 8;
    view1.textSHPhone.jk_maxLength = 11;
    view1.textPhone.jk_maxLength   = 11;
    view1.textName.jk_maxLength    = 8;
    view1.textKG.jk_maxLength      = 10;

    
    tcView.textToName.jk_maxLength  = 8;
    tcView.textToPhone.jk_maxLength = 11;
    tcView.textPhone.jk_maxLength   = 11;
    tcView.textName.jk_maxLength    = 8;
    tcView.textKG.jk_maxLength      = 10;

}

- (void)clickJJ{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"2公里范围内为6元\n超出2公里每公里多收2元" preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *action = [UIAlertAction actionWithTitle:@"知道了" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    
    [alert addAction:action];
    [self presentViewController:alert animated:YES completion:nil];
    
}
//同意服务协议
- (void)clickAgree:(UIButton *)btn{
    if (tcView.btnAgree.tag == 10) {
        [tcView.btnAgree setImage:[UIImage imageNamed:@"勾-(1)"] forState:UIControlStateNormal];
        
        tcView.btnAgree.tag = 20;
    }else{
        [tcView.btnAgree setImage:[UIImage imageNamed:@"矩形-7"] forState:UIControlStateNormal];
        
        tcView.btnAgree.tag = 10;
    }
}

- (void)clickService{
    ManServiceViewController *man = [[ManServiceViewController alloc] init];
    [self.navigationController pushViewController:man animated:YES
     ];
}

- (void)clickCar1{
    _labLine.hidden = NO;
    [UIView animateWithDuration:0.3 animations:^{
        _labLine.frame = CGRectMake((ScreenWidth/4-50)/2, 98, 50, 2);
    }];
    
    [_button1 setImage:[UIImage imageNamed:@"交通工具-电动车"] forState:UIControlStateNormal];
    [_button1 setTitleColor:COLOR_RGB(3, 191, 222, 1) forState:UIControlStateNormal];
    [_button2 setImage:[UIImage imageNamed:@"图层-4"] forState:UIControlStateNormal];
    [_button2 setTitleColor:COLOR_RGB(10, 11, 12, 1) forState:UIControlStateNormal];
    [_button3 setImage:[UIImage imageNamed:@"轿车"] forState:UIControlStateNormal];
    [_button3 setTitleColor:COLOR_RGB(10, 11, 12, 1) forState:UIControlStateNormal];
    [_button4 setImage:[UIImage imageNamed:@"货车"] forState:UIControlStateNormal];
    [_button4 setTitleColor:COLOR_RGB(10, 11, 12, 1) forState:UIControlStateNormal];
    _carType = @"1";
    [self loadDatas:@"1"];
}

- (void)clickCar2{
    _labLine.hidden = NO;
    [UIView animateWithDuration:0.3 animations:^{
        _labLine.frame = CGRectMake((ScreenWidth/4-50)/2+ScreenWidth/4, 98, 50, 2);
    }];
    
    [_button1 setImage:[UIImage imageNamed:@"-电动车"] forState:UIControlStateNormal];
    [_button1 setTitleColor:COLOR_RGB(10, 11, 12, 1) forState:UIControlStateNormal];
    [_button2 setImage:[UIImage imageNamed:@"图层-3"] forState:UIControlStateNormal];
    [_button2 setTitleColor:COLOR_RGB(3, 191, 222, 1) forState:UIControlStateNormal];
    [_button3 setImage:[UIImage imageNamed:@"轿车"] forState:UIControlStateNormal];
    [_button3 setTitleColor:COLOR_RGB(10, 11, 12, 1) forState:UIControlStateNormal];
    [_button4 setImage:[UIImage imageNamed:@"货车"] forState:UIControlStateNormal];
    [_button4 setTitleColor:COLOR_RGB(10, 11, 12, 1) forState:UIControlStateNormal];
    _carType = @"2";
    [self loadDatas:@"2"];
}

- (void)clickCar3{
    _labLine.hidden = NO;
    [UIView animateWithDuration:0.3 animations:^{
        _labLine.frame = CGRectMake((ScreenWidth/4-50)/2+ScreenWidth/2, 98, 50, 2);
    }];
    
    [_button1 setImage:[UIImage imageNamed:@"-电动车"] forState:UIControlStateNormal];
    [_button1 setTitleColor:COLOR_RGB(10, 11, 12, 1) forState:UIControlStateNormal];
    [_button2 setImage:[UIImage imageNamed:@"图层-4"] forState:UIControlStateNormal];
    [_button2 setTitleColor:COLOR_RGB(10, 11, 12, 1) forState:UIControlStateNormal];
    
    [_button3 setImage:[UIImage imageNamed:@"轿车2"] forState:UIControlStateNormal];
    [_button3 setTitleColor:COLOR_RGB(3, 191, 222, 1) forState:UIControlStateNormal];
    [_button4 setImage:[UIImage imageNamed:@"货车"] forState:UIControlStateNormal];
    [_button4 setTitleColor:COLOR_RGB(10, 11, 12, 1) forState:UIControlStateNormal];
    _carType = @"3";
    [self loadDatas:@"3"];
}

- (void)clickCar4{
    _labLine.hidden = NO;
    [UIView animateWithDuration:0.3 animations:^{
        _labLine.frame = CGRectMake((ScreenWidth/4-50)/2+ScreenWidth/4*3, 98, 50, 2);
    }];
    
    [_button1 setImage:[UIImage imageNamed:@"-电动车"] forState:UIControlStateNormal];
    [_button1 setTitleColor:COLOR_RGB(10, 11, 12, 1) forState:UIControlStateNormal];
    [_button2 setImage:[UIImage imageNamed:@"图层-4"] forState:UIControlStateNormal];
    [_button2 setTitleColor:COLOR_RGB(10, 11, 12, 1) forState:UIControlStateNormal];
    [_button3 setImage:[UIImage imageNamed:@"轿车"] forState:UIControlStateNormal];
    [_button3 setTitleColor:COLOR_RGB(10, 11, 12, 1) forState:UIControlStateNormal];
    
    [_button4 setImage:[UIImage imageNamed:@"货车2"] forState:UIControlStateNormal];
    [_button4 setTitleColor:COLOR_RGB(3, 191, 222, 1) forState:UIControlStateNormal];
    _carType = @"4";
    [self loadDatas:@"4"];
}
//同城快递价格获取
- (void)loadDatas:(NSString *)cartype{
//    NSString *str = [NSString stringWithFormat:@"%@890d69e502d1d37a9e84335ccefece57",[user objectForKey:@"token2"]];
    NSString *token = [user objectForKey:@"token2"];
    
    NSMutableDictionary *parmas = [NSMutableDictionary dictionary];
    [parmas setObject:token forKey:@"verifiToken"];
    [parmas setObject:[user objectForKey:@"userid"] forKey:@"userid"];
    [parmas setObject:cartype forKey:@"cartype"];
    NSLog(@"parmas:%@",parmas);
    NSString *url = [NSString stringWithFormat:@"%@/App/Expressage/cityExpressPrice",urlHead];
    [[AFHTTPSessionManager manager] POST:url parameters:parmas success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"同城快递价格获取res:%@",responseObject);
        _priceKm = [responseObject objectForKey:@"result"];
        
        tcView.labQBJ.text = [NSString stringWithFormat:@"起步价：%@元",[_priceKm objectForKey:@"start_price"]];
        tcView.labDJ.text = [NSString stringWithFormat:@"每公里单价：%@元",[_priceKm objectForKey:@"per_price"]];
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"error:%@",error);
    }];
}

#pragma mark - UITextViewDelegate
-(void)textViewDidBeginEditing:(UITextView *)textView{
    if ([textView.text isEqualToString:@"请填写"]) {
        textView.text = @"";
        textView.textColor = [UIColor blackColor];
    }
}

-(void)textViewDidEndEditing:(UITextView *)textView{
    
    if (textView.text.length < 1) {
        textView.text = @"请填写";
        textView.textColor = [UIColor grayColor];
    }
}

-(void)textViewDidChange:(UITextView *)textView{
    if (textView == view1.textView) {
        NSInteger count = textView.text.length;
        view1.labLength.text = [NSString stringWithFormat:@"%li/100",count];
    }else if (textView == tcView.textView){
        NSInteger count = textView.text.length;
        tcView.labLength.text = [NSString stringWithFormat:@"%li/100",count];
    }

    
    //限制长度
    if (textView.text.length >100) {
        textView.text = [textView.text substringWithRange:NSMakeRange(0, 100)];
        [textView.undoManager removeAllActions];
        [textView becomeFirstResponder];
        return;
    }
}

//全国快递
- (void)click1{
    view1.hidden = NO;
    view2.hidden = YES;
    sclView.contentSize = CGSizeMake(ScreenWidth, 667);
    
    btn1.backgroundColor = COLOR_RGB(253, 17, 66, 1);
    [btn1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    btn2.backgroundColor = [UIColor whiteColor];
    [btn2 setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    btn2.layer.borderWidth = 1.0;
    btn2.layer.borderColor =COLOR_RGB(253, 17, 66, 1).CGColor;
    
}
//同城快递
- (void)click2{
    view1.hidden = YES;
    view2.hidden = NO;
    sclView.contentSize = CGSizeMake(ScreenWidth, 950);
    view2.frame = CGRectMake(0, 0, ScreenWidth, 950);
    
    btn1.backgroundColor = [UIColor whiteColor];
    [btn1 setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    btn1.layer.borderColor = [UIColor redColor].CGColor;
    btn1.layer.borderWidth = 1.0;
    
    btn2.backgroundColor = COLOR_RGB(253, 17, 66, 1);
    [btn2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
}
//取件地址
- (void)click1QG{
    MapSelPlaceViewController *map = [[MapSelPlaceViewController alloc] init];
    map.delegate = self;
    _placeState = @"aaa";
    [self.navigationController pushViewController:map animated:YES];
}
#pragma -mark MapSelPlaceViewControllerDelegate
-(void)sendText:(NSString *)text Province:(NSString *)proce City:(NSString *)city Area:(NSString *)area{
    
}

-(void)sendAddress:(NSString *)address Det:(NSString *)det{
    if ([_placeState isEqualToString:@"aaa"]) {
        view1.labQJDZ.text = det;
        view1.labJieDao.text = address;
    }else if ([_placeState isEqualToString:@"sss"]){
        tcView.labGoPlace.text = det;
        tcView.labGoJieDao.text = address;
    }else{
        tcView.labToPlace.text = det;
        tcView.labToJieDao.text = address;
    }
}

-(void)sendLat:(NSString *)lat sendLng:(NSString *)lng{
    if ([_placeState isEqualToString:@"aaa"]) {
        _lat = lat;
        _lng = lng;
    }else if ([_placeState isEqualToString:@"sss"]){
        _lat1 = lat;
        _lng1 = lng;
        NSLog(@"lat1:%@ lng1:%@",_lat1,_lng1);
    }else{
        _lat2 = lat;
        _lng2 = lng;
        NSLog(@"lat2:%@ lng2:%@",_lat2,_lng2);
        [self loadPace];//km
    }
    
}

//选择省市区
- (void)click2QG{
//    bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, ScreenHeight-250, ScreenWidth, 250)];
//    bottomView.backgroundColor = [UIColor grayColor];
//    [self.view addSubview:bottomView];
//
//    UIButton *btnCancel = [UIButton buttonWithType:UIButtonTypeCustom];
//    btnCancel.frame = CGRectMake(10, 0, 40, 40);
//    [btnCancel setTitle:@"取消" forState:UIControlStateNormal];
//    [btnCancel setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
//    [btnCancel addTarget:self action:@selector(clickCancel1) forControlEvents:UIControlEventTouchUpInside];
//    [bottomView addSubview:btnCancel];
//
//    UIButton *btnSure = [UIButton buttonWithType:UIButtonTypeCustom];
//    btnSure.frame = CGRectMake(ScreenWidth-50, 0, 40, 40);
//    [btnSure setTitle:@"确定" forState:UIControlStateNormal];
//    [btnSure setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
//    [btnSure addTarget:self action:@selector(clickSure1) forControlEvents:UIControlEventTouchUpInside];
//    [bottomView addSubview:btnSure];
//
//    self.pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 40, ScreenWidth, 210)];
//    self.pickerView.dataSource = self;
//    self.pickerView.delegate = self;
//    [bottomView addSubview:self.pickerView];
    
//    bottomView.hidden = NO;
    
    AddressPickerView *address = [AddressPickerView showSelectCity];
    address.delegate = self;
    
}

#pragma mark -- addressDelegate
-(void)sureBtnClickReturnProvince:(NSString *)province City:(NSString *)city Area:(NSString *)area
{
    
    NSString *address = [NSString stringWithFormat:@"%@-%@-%@", province, city, area];
    NSLog(@"address:%@",address);
    _Province = province;
    _City = city;
    _Area = area;
    view1.labGOPlace.text = address;
}

//
- (void)clickCancel1{
    bottomView.hidden = YES;
}

- (void)clickSure1{
    bottomView.hidden = YES;
}
//从地址
- (void)clicktc1{
    MapSelPlaceViewController *map = [[MapSelPlaceViewController alloc] init];
    map.delegate = self;
    _placeState = @"sss";
    [self.navigationController pushViewController:map animated:YES];
}
//到地址
- (void)clicktc2{
    MapSelPlaceViewController *map = [[MapSelPlaceViewController alloc] init];
    map.delegate = self;
    _placeState = @"ddd";
    [self.navigationController pushViewController:map animated:YES];
}

//选择快递
- (void)clickKD{
    
    UIView *pickerContent = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    [window addSubview:pickerContent];
    pickerContent.userInteractionEnabled = YES;
    pickerContent.backgroundColor = COLOR_RGB(90, 90, 90, 0.5);
    _pickerContent = pickerContent;
    
    footView = [[UIView alloc] initWithFrame:CGRectMake(0, ScreenHeight-240, ScreenWidth, 240)];
    footView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [_pickerContent addSubview:footView];

    UIButton *btnCancel = [UIButton buttonWithType:UIButtonTypeCustom];
    btnCancel.frame = CGRectMake(30, 0, 40, 40);
    [btnCancel setTitle:@"取消" forState:UIControlStateNormal];
    [btnCancel setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [btnCancel addTarget:self action:@selector(clickCancel) forControlEvents:UIControlEventTouchUpInside];
    [footView addSubview:btnCancel];

    UIButton *btnSure = [UIButton buttonWithType:UIButtonTypeCustom];
    btnSure.frame = CGRectMake(ScreenWidth-70, 0, 40, 40);
    [btnSure setTitle:@"确定" forState:UIControlStateNormal];
    [btnSure setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [btnSure addTarget:self action:@selector(clickSure) forControlEvents:UIControlEventTouchUpInside];
    [footView addSubview:btnSure];

    _picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 40, ScreenWidth, 200)];
    _picker.delegate = self;
    _picker.dataSource = self;
    _picker.backgroundColor = [UIColor whiteColor];
    [footView addSubview:_picker];
    _pickerContent.hidden = NO;
    footView.hidden = NO;
    
}

- (void)clickCancel{
    footView.hidden = YES;
    _pickerContent.hidden = YES;
}

- (void)clickSure{
    footView.hidden = YES;
    _pickerContent.hidden = YES;

}

#pragma mark - PickerView Delegate
// 列数
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    if (pickerView==self.pickerView) {
        return 3;
    }else{
        return 1;
    }
    
}

// 每列有多少行
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    if (pickerView == self.pickerView) {
        if(component == 0){
            return self.regionArray.count;
        }
        else if (component == 1){
            return [self.regionArray[self.provinceIndex][@"citys"] count];
        }
        else{
            return [self.regionArray[self.provinceIndex][@"citys"][self.cityIndex][@"districts"] count];
        }
    }else{
        return array.count;
    }
    
}
// 返回每一行的内容
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    if (pickerView == self.pickerView) {
        if(component == 0){
            return self.regionArray[row][@"province"];
        }
        else if (component == 1){
            return self.regionArray[self.provinceIndex][@"citys"][row][@"city"];
        }
        else{
            return self.regionArray[self.provinceIndex][@"citys"][self.cityIndex][@"districts"][row];
        }
    }else{
        NSDictionary *dic = array[row];
        NSString *name = [dic objectForKey:@"expressname"];
        return name;
    }
}

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
    if (pickerView == self.pickerView) {
        UILabel* pickerLabel = (UILabel*)view;
        if (!pickerLabel){
            pickerLabel = [[UILabel alloc] init];
            pickerLabel.adjustsFontSizeToFitWidth = YES;
            [pickerLabel setTextAlignment:NSTextAlignmentCenter];
            [pickerLabel setBackgroundColor:[UIColor clearColor]];
            [pickerLabel setFont:[UIFont boldSystemFontOfSize:15]];
        }
        // Fill the label text here
        pickerLabel.text=[self pickerView:pickerView titleForRow:row forComponent:component];
        return pickerLabel;
    }else{
        UILabel *lab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 40)];
        lab.textAlignment = NSTextAlignmentCenter;
        NSDictionary *dic = array[row];
        NSString *name = [dic objectForKey:@"expressname"];
        lab.text = name;
        
        return lab;
    }
}

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
    if (pickerView == self.pickerView) {
        if(component == 0){
            self.provinceIndex = row;
            self.cityIndex = 0;
            self.districtIndex = 0;
            
            [self.pickerView reloadComponent:1];
            [self.pickerView reloadComponent:2];
        }
        else if (component == 1){
            self.cityIndex = row;
            self.districtIndex = 0;
            
            [self.pickerView reloadComponent:2];
        }
        else{
            self.districtIndex = row;
        }
        [self resetPickerSelectRow];
    }else{
        NSDictionary *dic = array[row];
        NSString *name = [dic objectForKey:@"expressname"];
        self.kdid = [dic objectForKey:@"id"];
        view1.labSelKD.text = name;
        NSLog(@"name=%@,kdid=%@",name,self.kdid);
    }
}
//选择区域
-(void)resetPickerSelectRow
{
    [self.pickerView selectRow:self.provinceIndex inComponent:0 animated:YES];
    [self.pickerView selectRow:self.cityIndex inComponent:1 animated:YES];
    [self.pickerView selectRow:self.districtIndex inComponent:2 animated:YES];
    NSString *province = self.regionArray[self.provinceIndex][@"province"];
    NSString *city = self.regionArray[self.provinceIndex][@"citys"][self.cityIndex][@"city"];
    NSString *distric = self.regionArray[self.provinceIndex][@"citys"][self.cityIndex][@"districts"][self.districtIndex];
    NSString *address = [NSString stringWithFormat:@"%@-%@-%@", province, city, distric];
    NSLog(@"address:%@",address);
    _Province = province;
    _City = city;
    _Area = distric;
    view1.labGOPlace.text = address;
}

//全国快递
- (void)clickHJ{
    if (![user objectForKey:@"userid"]) {
        LoginViewController *login = [[LoginViewController alloc] init];
        NavViewController *nav = [[NavViewController alloc] initWithRootViewController:login];
        nav.navigationBarHidden = YES;
        [self presentViewController:nav animated:YES completion:nil];
        return;
    }
    
    if ([view1.labQJDZ.text isEqualToString:@"地址"]) {
        
        [LICGToast showWithText:@"请选择取件地址"];
        return;
    }else if (view1.textQJDet.text.length == 0){

        [LICGToast showWithText:@"请输入详细地址"];
        return;
    }else if (view1.textName.text.length == 0){

        [LICGToast showWithText:@"请输入姓名"];
        return;
    }else if ([self validateMobile:view1.textPhone.text] == 0){
        
        [LICGToast showWithText:@"联系电话格式不正确"];
        return;
    }else if ([view1.labGOPlace.text isEqualToString:@"请选择省市区"]){
        
        [LICGToast showWithText:@"请选择省市区"];
        return;
    }else if (view1.textGoDet.text.length == 0){

        [LICGToast showWithText:@"请输入详细地址"];
        return;
    }else if (view1.textSHName.text.length == 0){
        
        [LICGToast showWithText:@"请输入收货人姓名"];
        return;
    }else if ([self validateMobile:view1.textSHPhone.text] == 0){

        [LICGToast showWithText:@"收货人电话格式不正确"];
        return;
    }else if (view1.textKG.text.length == 0){

        [LICGToast showWithText:@"请输入物品重量"];
        return;
    }else if ([view1.labSelKD.text isEqualToString:@"请选择"]){
        
        [LICGToast showWithText:@"请选择快递公司"];
        return;
    }
    
    NSMutableDictionary *parmas = [NSMutableDictionary dictionary];
    [parmas setObject:[user objectForKey:@"userid"] forKey:@"userid"];
    [parmas setObject:self.kdid forKey:@"expressid"];
    [parmas setObject:view1.labQJDZ.text forKey:@"upaddress"];
    [parmas setObject:view1.textQJDet.text forKey:@"housenumber"];
    [parmas setObject:_Province forKey:@"goprovince"];
    [parmas setObject:_City forKey:@"gocity"];
    [parmas setObject:_Area forKey:@"gozone"];
    [parmas setObject:view1.textGoDet.text forKey:@"goaddress"];
    [parmas setObject:view1.textKG.text forKey:@"weight"];
    
    if (![view1.textView.text isEqualToString:@"请填写"]) {
        [parmas setObject:view1.textView.text forKey:@"ordername"];//备注
    }
    [parmas setObject:_lat forKey:@"latitude"];
    [parmas setObject:_lng forKey:@"longitude"];
//    [parmas setObject:@"2" forKey:@"payment"];
//    [parmas setObject:@"1" forKey:@"ordermoney"];
    [parmas setObject:_orderNum forKey:@"ordernumber"];
    [parmas setObject:view1.textPhone.text forKey:@"sendphone"];
    [parmas setObject:view1.textSHPhone.text forKey:@"takephone"];
    [parmas setObject:view1.textName.text forKey:@"sendusername"];
    [parmas setObject:view1.textSHName.text forKey:@"takeusername"];
    
    PayForViewController *pay = [[PayForViewController alloc] init];
    pay.OrderName = @"全国快递";
    pay.dic = parmas;
    pay.price = @"1";
    [self.navigationController pushViewController:pay animated:YES];
    
}

//同城
- (void)clickTChj{
    if (![user objectForKey:@"userid"]) {
        LoginViewController *login = [[LoginViewController alloc] init];
        NavViewController *nav = [[NavViewController alloc] initWithRootViewController:login];
        nav.navigationBarHidden = YES;
        [self presentViewController:nav animated:YES completion:nil];
        return;
    }
    
    if ([tcView.labGoPlace.text isEqualToString:@"地址"]) {

        [LICGToast showWithText:@"请选择寄件地址"];
        return;
    }else if ([tcView.textGoDet.text isEqualToString:@"地址"]){
        
        [LICGToast showWithText:@"请输入详细地址"];
        return;
    }else if (tcView.textName.text.length == 0){
        
        [LICGToast showWithText:@"请输入寄件人姓名"];
        return;
    }else if ([self validateMobile:tcView.textPhone.text] == 0){
        
        [LICGToast showWithText:@"寄件人电话格式不正确"];
        return;
    }else if ([tcView.labToPlace.text isEqualToString:@"请选择"]){

        [LICGToast showWithText:@"请选择收件地址"];
        return;
    }else if (tcView.textToDet.text.length == 0){

        [LICGToast showWithText:@"请输入收件详细地址"];
        return;
    }else if (tcView.textToName.text.length == 0){

        [LICGToast showWithText:@"请输入收件人姓名"];
        return;
    }else if ([self validateMobile:tcView.textToPhone.text] == 0){

        [LICGToast showWithText:@"收件人电话格式不正确"];
        return;
    }else if (tcView.textKG.text.length == 0){
        
        [LICGToast showWithText:@"请输入物品重量"];
        return;
    }else if (tcView.btnAgree.tag == 10){
        [LICGToast showWithText:@"请同意丫丢丢用户服务协议"];
        return;
    }else if (_carType.length == 0){

        [LICGToast showWithText:@"请选择交通工具"];
        return;
    }
    
    NSMutableDictionary *parmas = [NSMutableDictionary dictionary];
    [parmas setObject:[user objectForKey:@"userid"] forKey:@"userid"];
    [parmas setObject:_carType forKey:@"cartype"];
    //送件地址
    [parmas setObject:tcView.labToPlace.text forKey:@"sendaddress"];
    [parmas setObject:tcView.textToDet.text forKey:@"senddetail"];
    //取件地址
    [parmas setObject:tcView.labGoPlace.text forKey:@"takeaddress"];
    [parmas setObject:tcView.textGoDet.text forKey:@"takedetail"];
    //送件人电话
    [parmas setObject:tcView.textPhone.text forKey:@"sendphone"];
    [parmas setObject:tcView.textName.text forKey:@"sendusername"];
    //取件人电话
    [parmas setObject:tcView.textToPhone.text forKey:@"takephone"];
    [parmas setObject:tcView.textToName.text forKey:@"takeusername"];
    [parmas setObject:tcView.textKG.text forKey:@"weight"];
    if (![tcView.textView.text isEqualToString:@"请填写"]) {
        [parmas setObject:tcView.textView.text forKey:@"remark"];
    }
    [parmas setValue:_km forKey:@"stroke"];//行程
    [parmas setValue:_lng2 forKey:@"sendlongitude"];
    [parmas setValue:_lat2 forKey:@"sendlatitude"];
    [parmas setValue:_lng1 forKey:@"takelongitude"];
    [parmas setValue:_lat1 forKey:@"takelatitude"];
//    [parmas setObject:@"2" forKey:@"payment"];
    [parmas setValue:_km forKey:@"distance"];
    
    PayForViewController *pay = [[PayForViewController alloc] init];
    pay.dic = parmas;
    pay.OrderName = @"同城快递";
    pay.price = _tcPrice;
    [self.navigationController pushViewController:pay animated:YES];
    
}

//距离
- (void)loadPace{
    NSMutableDictionary *parmas = [NSMutableDictionary dictionary];
    [parmas setObject:_lng1 forKey:@"start_longitude"];
    [parmas setObject:_lat1 forKey:@"start_latitude"];
    [parmas setObject:_lng2 forKey:@"end_longitude"];
    [parmas setObject:_lat2 forKey:@"end_latitude"];
    NSLog(@"parmas:%@",parmas);
    NSString *url = [NSString stringWithFormat:@"%@/App/Banner/km",urlHead];
    [[AFHTTPSessionManager manager] POST:url parameters:parmas success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"res:%@",responseObject);
        _km = [[responseObject objectForKey:@"result"] objectForKey:@"km"];
        NSString *qbj = [_priceKm objectForKey:@"start_price"];
        NSString *dj = [_priceKm objectForKey:@"per_price"];
        CGFloat a = [qbj floatValue];
        CGFloat b = [dj floatValue];
        CGFloat c = [_km floatValue];
        CGFloat price = a+b*c;
        tcView.labKM.text = [NSString stringWithFormat:@"%@公里",_km];
        _tcPrice = [NSString stringWithFormat:@"%.2f",price];
        tcView.labPrice.text = [NSString stringWithFormat:@"%.2f元",price];
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"error:%@",error);
    }];
    
}

//快递-店铺列表
- (void)loadData{
    NSMutableDictionary *parmas = [NSMutableDictionary dictionary];
    NSString *url = [NSString stringWithFormat:@"%@/App/Expressage/index",urlHead];
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager POST:url parameters:parmas success:^(NSURLSessionDataTask *task, id responseObject) {
        //NSLog(@"res:%@",responseObject);
        array = [responseObject objectForKey:@"result"];
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"error:%@",error);
    }];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
